<%@page contentType="text/html;charset=UTF-8"%>
<%@page pageEncoding="UTF-8"%>
<%
	String grpid = request.getParameter("grpid");
%>
<%@ include file="/pub/includ.jsp"%>
<html>
	<head>
		<script type="text/javascript">
		
			$(function(){
				//加载两个要使用json分页的组�?
		        loadGird("frm", 1);
			})
				
			var callback_frm = function(rows, frm) {
		       $.each(rows, function(i, n){
		    	   var row = $("#"+frm+" .template").clone().removeClass("template");
		   			       var keyValue = n.id;
			       row.find(".klId").attr("value",n.id);
			   	   
			       row.find(".klart_name").text(n.art_name.substr(0,30));
			   	
			       row.find(".klauthor").text(n.author);
			   	
			       row.find(".klcreate_time").text((new Date(n.create_time)).format("yyyy-MM-dd hh:mm"));
			   	
			       row.find(".klstatus").text(n.status);
			   	
		 		   row.attr("id","ready"+i);
		           row.attr("class","tr_nbw");
		           row.appendTo("#"+frm+" .grid");
		       });   
			}
			
			var delarticles = function(){
				var options = {
				type: 'POST',
				async: false,
				dataType: 'content-type',
				success: function(msg) {
						alert("成功删除"+msg+"条记录!");
						window.location.reload();
					}
				}
				if(confirm('您确认要删除吗？')){
					document.getElementById("frm").action="<%=path%>/cms/article/delarticles";
					$('#frm').ajaxSubmit(options);
				}
			}
			function parentCallback(){
				loadGird("frm", 1);
			}
			function addarticle(){
				if("<%=grpid %>" == ""){
					top.alertMsg("请选择文章组～");
				}else if("<%=grpid %>" == "ROOT"){
					top.alertMsg("不能往根目录添加文章组");
				}else{
					window.open("<%=path %>/cms/article/toForm/0?grpid=<%=grpid %>");
				}
			}
			
			function modifyarticle(id){
				var chks = document.getElementsByName("chk");
				var k=0;
				var id="";
				for(var i=0;i<chks.length;i++){
					if(chks[i].checked==true){
						k++;
						id=chks[i].value;
					}
				}
				if(k==0){
					alert("请选择一条要修改的记录！");
				}
				if(k>1){
					alert("只能选择一条要修改的记录！");
				}
				if(k==1){
					window.open("<%=path %>/cms/article/toForm/"+id);
				}
			}
		</script>
	</head>
<body>
<form name="frm" method="post" style="margin: 0" action="<%=path%>/cms/article/list?grpid=<%=grpid %>" id="frm">
		<table width="100%">
			<tr>
				<td height="2px"></td>
			</tr>
			<tr><td align="right">
				<input type="button" onclick="addarticle();" class="button4_nbw" value="添加" />
				<input type="button" onclick="modifyarticle();" class="button4_nbw" value="修改" />
				<input type="button" onclick="delarticles()" class="button4_nbw" value="删除" />
				&nbsp;&nbsp;
				</td>
			</tr>
		</table>
		<center>
		<table><tr><td height="2px"></td></tr></table>
		<table border="0" cellspacing="1" cellpadding="0" class="table_nbw  niceTable grid">
			<thead class="th_nbw">
				<tr >
					<td width="40px" >
						<input type="checkbox" class="allCheck" />
					</td>
		      		<td width="40%">
						文章名称
					</td>   
		      		<td>
						作者
					</td>    
		      		<td>
						创建时间
					</td>   
		      		<td>
						状态
					</td>  
				</tr>
			</thead>
			<tbody>
				<tr class="template klId">
					<td width="40px" class="idCheck">
						<input type="checkbox" name="chk" class="klId" />
					</td>
		   		    <td class="klart_name niceTable-left"></td>
		   		    <td class="klauthor niceTable-left"></td>
		   		    <td class="klcreate_time niceTable-left"></td>
		   		    <td class="klstatus niceTable-left"></td>
				</tr>
			</tbody>
			<tfoot>
				<tr>
					<td style="border-right: none">
						<img class="loading"
							src="<%=path %>/resources/skins/default/images/large-loading.gif" width="20px"
							class="hidden" />
					</td>
					<td colspan="4" style="border-left: none" class="txtRight">
						<span class="pagediv"></span>
					</td>
				</tr>
			</tfoot>
		</table>
		</center>
	</form>
</body>
</html>
